package com.chen.androidstudy.activity

import android.content.Intent
import android.telecom.TelecomManager
import android.util.Log
import com.base.library.base.ActivityCallback
import com.base.library.base.BaseVM
import com.chen.androidstudy.App
import com.chen.androidstudy.utils.ImageUtil
import com.chen.androidstudy.utils.Logger
import com.chen.androidstudy.utils.UriUtils
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

/**
 *
 * @Author:        CHong
 * @CreateDate:    2024/2/27 0027
 * @Description:
 */
@HiltViewModel
class IntentViewModel @Inject constructor() : BaseVM() {

    override fun initData() {

    }

    fun onCallSetting() {
        val intent = Intent(TelecomManager.ACTION_SHOW_CALL_SETTINGS)
//        if (intent.resolveActivity(context.getPackageManager()) != null) {
        startActivity(intent)
//        }
    }

    fun onImageChoose() {
        val intent = Intent()
        intent.action = Intent.ACTION_PICK
//        MediaStore.Images.Media.EXTERNAL_CONTENT_URI
//        MediaStore.Video.Media.EXTERNAL_CONTENT_URI
        intent.type = "image/*"
//        intent.type = "video/*"
//        startActivityForResult(intent, MainActivity.REQUEST_IMAGE)
        startActivity(intent, object : ActivityCallback {
            override fun invoke(resultCode: Int, data: Intent?) {
                data?.let {
                    val uri = it.data
//                    val path = ImageUtil.getImageAbsolutePath(App.instance, uri)
                    val path =  UriUtils.getFilePath(App.instance, uri)
                    Logger.e("chen", "path:$path")
                }
            }
        })
    }

}